package com.tree.backend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tree.backend.entity.pojo.PartyActivity;
import com.tree.backend.entity.vo.ActivityTrend;
import com.tree.backend.entity.vo.OrgActivityStats;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 党建活动记录表，记录各类党建活动的基本信息和成果 Mapper 接口
 * </p>
 *
 * @author tree
 * @since 2025-10-15
 */
public interface PartyActivityMapper extends BaseMapper<PartyActivity> {

    @Select("select po.org_name as \"organizationNames\" , count(1) as \"activityCounts\" , sum(pa.participant_count) as \"participantCounts\"\n" +
            "from party_organization po, party_activity pa\n" +
            "where po.org_code = pa.org_code\n" +
            "group by po.org_code\n" +
            "order by count(1) asc\n" +
            "limit 0,8;")
    List<OrgActivityStats> organizationStats();

    @Select("select activity_type as \"activityTypes\",\n" +
            "       count(1) as \"activityCounts\",\n" +
            "       round(avg(achievement_level),2) as \"avgAchievementLevels\"\n" +
            "from party_activity group by activity_type\n" +
            "order by activity_type;")
    List<ActivityTrend> trend();
}
